package de.fzi.kasma.learner.genetic;


import ec.BreedingPipeline;
import ec.EvolutionState;
import ec.Individual;
import ec.util.Parameter;

public class RLMutationPipeline extends BreedingPipeline {

    /**
	 * 
	 */
	private static final long serialVersionUID = 4547216905973925427L;
	public static final String P_MUTATION = "mutate";
    public static final int INDS_PRODUCED = 1;
    public static final int NUM_SOURCES = 1;
    
	@Override
	public int numSources() {
		// 
		return NUM_SOURCES;
	}
	
	 /** Returns 1 */
    // DO I need to change this?
    public int typicalIndsProduced() { return (INDS_PRODUCED); }

	@Override
	public int produce(int min, int max, int start, int subpopulation,
			Individual[] inds, EvolutionState state, int thread) {
		// TODO Auto-generated method stub
	     // grab n individuals from our source and stick 'em right into inds.
        // we'll modify them from there
        int n = sources[0].produce(min,max,start,subpopulation,inds,state,thread);

        // clone the individuals if necessary
        if (!(sources[0] instanceof BreedingPipeline))
            for(int q=start;q<n+start;q++)
                inds[q] = (Individual)(inds[q].clone());

        // mutate 'em
        // TODO: Do the refinement here... and call join or reset of the individual 
        // to either drop, replace or add a clause
        for(int q=start;q<n+start;q++)
            {

            ((RLIndividual)inds[q]).preprocessIndividual(state,thread);

            int len = ((RLIndividual)inds[q]).clauses.length;

            for( int x = 0 ; x < len ; x++ )
                {
//                ((RLIndividual)inds[q]).clauses[x].mutateEdges( state, thread );
                }
            ((RLIndividual)inds[q]).evaluated=false;
            ((RLIndividual)inds[q]).postprocessIndividual(state,thread);
            }

        return n;
        
	}

	@Override
	public Parameter defaultBase() {
		// 
		return RLDefaults.base().push(P_MUTATION);
	}

}
